package javase.thread.threadPool;

import java.util.concurrent.*;

public class ThreadPoolFactory {
    private static volatile ExecutorService executorService = null;
    private ThreadPoolFactory(){}

    public static ExecutorService builder(){
        if (executorService==null){
            synchronized (ThreadPoolFactory.class){
                if (executorService==null){
                    executorService = new ThreadPoolExecutor(5,
                            10,
                            10,
                            TimeUnit.MINUTES,
                            new ArrayBlockingQueue<Runnable>(100),
                            Executors.defaultThreadFactory(),
                            new ThreadPoolExecutor.CallerRunsPolicy());
                }
            }
        }
        return executorService;
    }
}
